<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Dweebd::HasManyWithArgs::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Dweebd::HasManyWithArgs::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/lib/has_many_with_args_rb.html">
                lib/has_many_with_args.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000001">has_many_with_args</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="InstanceMethods.html">HasManyWithArgs::InstanceMethods</a></span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000001" class="method-detail">
        <a name="M000001"></a>

        <div class="method-heading">
          <a href="#M000001" class="method-signature">
          <span class="method-name">has_many_with_args</span><span class="method-args">(association_id, *args, &amp;extension)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Define an association that takes arguments other than force_reload. An
arbitrary number of arguments can be specified and they will all be
mandatory. Optional arguments are not currently supported.
</p>
<p>
First the association name is defined, followed by the arguments the method
takes
</p>
<pre>
  class Referee
    has_many_with_args :officiated_fights_between :fighter1, :fighter2
  end
</pre>
<p>
Then it can be accessed on instances of Referee
</p>
<pre>
  ref = Referee.find(1)
  ali     = Boxer.find(1)
  foreman = Boxer.find(2)

  ref.officiated_fights_between(ali, foreman)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000001-source">
<pre>
    <span class="ruby-comment cmt"># File lib/has_many_with_args.rb, line 23</span>
23:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_many_with_args</span>(<span class="ruby-identifier">association_id</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">extension</span>)
24:         <span class="ruby-identifier">include</span> <span class="ruby-constant">HasManyWithArgs</span><span class="ruby-operator">::</span><span class="ruby-constant">InstanceMethods</span>
25:         <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>
26:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'Must specify at least one argument for association to take'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
27:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'Must specify class name of association objects.  Use :class_name in has_many_with_args options'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:class_name</span>)
28: 
29:         <span class="ruby-identifier">args_and_accessors</span> = <span class="ruby-identifier">args_and_accessors_for</span>(<span class="ruby-identifier">association_id</span>, <span class="ruby-identifier">args</span>)
30:         <span class="ruby-identifier">create_attr_readers</span> <span class="ruby-identifier">args_and_accessors</span>.<span class="ruby-identifier">values</span>
31:         <span class="ruby-identifier">new_options</span> = <span class="ruby-identifier">remapped_options</span> <span class="ruby-identifier">options</span>, <span class="ruby-identifier">args_and_accessors</span>
32: 
33:         <span class="ruby-identifier">mapped_association_id</span> = <span class="ruby-node">&quot;has_many_with_args_mapped_association_#{association_id}&quot;</span>
34:         <span class="ruby-identifier">has_many</span> <span class="ruby-identifier">mapped_association_id</span>, <span class="ruby-identifier">new_options</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">extension</span>
35: 
36:         <span class="ruby-constant">InstanceMethods</span>.<span class="ruby-identifier">define_association_accessor</span> <span class="ruby-identifier">mapped_association_id</span>, <span class="ruby-identifier">association_id</span>, <span class="ruby-identifier">args_and_accessors</span>
37:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>